package com.gitee.faster.webdav.kernel.model;

import cn.hutool.core.collection.CollUtil;
import jakarta.xml.bind.annotation.*;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;

/**
 * 多值响应
 *
 * @author hongda.li
 */
@SuppressWarnings("SpellCheckingInspection")
@Data
@Accessors(chain = true)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
        "response",
        "responseDescription",
        "syncToken"
})
@XmlRootElement(name = "multistatus")
public class MultiStatus {

    /**
     * 每个 response 代表对一个资源的请求的结果
     */
    @XmlElement(required = true)
    private List<Response> response;

    /**
     * 响应描述
     */
    @XmlElement(name = "responsedescription")
    private String responseDescription;

    /**
     * 同步 Token 标记
     */
    @XmlElement(name = "sync-token")
    @XmlSchemaType(name = "anyURI")
    private String syncToken;

    public void addResponse(Response response) {
        if (this.response == null) {
            this.response = new ArrayList<>();
        }
        this.response.add(response);
    }

    public Response lastResponse() {
        return CollUtil.getLast(this.response);
    }
}
